/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package elaborate.h2x.transform;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

/**
 *
 * @author lendle
 */
public class DefaultTransformingModelImpl implements TransformingModel{
    private Map<TransformingNodeId, TransformingNode> nodeMap=new HashMap<TransformingNodeId, TransformingNode>();
    private Map<Node, TransformingNode> domNodeMap=new HashMap<Node, TransformingNode>();
    private Map<TransformingNode, TransformingNode> nearestEnclosingMap=new HashMap<TransformingNode, TransformingNode>();
    protected Document document;
    protected List<TransformingNode> roots = new  ArrayList<TransformingNode>();

    /**
     * Get the value of roots
     *
     * @return the value of roots
     */
    public List<TransformingNode> getRoots() {
        return roots;
    }

    /**
     * Get the value of document
     *
     * @return the value of document
     */
    public Document getDocument() {
        return document;
    }

    /**
     * Set the value of document
     *
     * @param document new value of document
     */
    public void setDocument(Document document) {
        this.document = document;
    }

    
    public TransformingNode getNode(TransformingNodeId id) {
        return this.nodeMap.get(id);
    }

    public TransformingNode getNearestEnclosingNode(TransformingNode node) {
        return this.nearestEnclosingMap.get(node);
    }

    public Iterator<TransformingNode> iterateAllNodes() {
        return this.nodeMap.values().iterator();
    }
    
    public void putNode(TransformingNodeId id, TransformingNode node){
        this.nodeMap.put(id, node);
        this.domNodeMap.put(node.getOriginalNode(), node);
    }

    public void setNearestEnclosingRelationship(TransformingNode enclosingNode, TransformingNode enclosedNode){
        this.nearestEnclosingMap.put(enclosedNode, enclosingNode);
    }

    public TransformingNode getNode(Node node) {
        return domNodeMap.get(node);
    }
}
